import React from 'react'
import { Table } from 'antd'

const columns = [
    {
        title: '名称',
        dataIndex: 'name',
        key: 'name',
    },
    {
        title: '文件大小(KB)',
        dataIndex: 'fileSize',
        key: 'fileSize',
    },
    {
        title: '内存大小(KB)',
        dataIndex: 'memSize',
        key: 'memSize',
    },
    {
        title: '贴图大小',
        dataIndex: 'imgBound',
        key: 'imgBound',
    },
    {
        title: '文件格式',
        dataIndex: 'fileFormat',
        key: 'fileFormat',
    },
    {
        title: '类型',
        dataIndex: 'fileType',
        key: 'fileType',
    }
];

const overallcolumns = [
    {
        title: '文件',
        dataIndex: 'fileName',
        key: 'fileName',
    },
    {
        title: '总Drawcall',
        dataIndex: 'totalDrawCall',
        key: 'totalDrawCall',
    },
    {
        title: 'UI Drawcall',
        dataIndex: 'uiDrawCall',
        key: 'uiDrawCall',
    },
    {
        title: '玩家Drawcall',
        dataIndex: 'playerDrawCall',
        key: 'playerDrawCall',
    },
    {
        title: '场景Drawcall',
        dataIndex: 'stageDrawCall',
        key: 'stageDrawCall',
    },
    {
        title: '总内存(MB)',
        dataIndex: 'totalMemeCache',
        key: 'totalMemeCache',
    },
    {
        title: '3D内存(MB)',
        dataIndex: 'threeDMemeCache',
        key: 'threeDMemeCache',
    },
    {
        title: '2D内存(MB)',
        dataIndex: 'twoDMemeCache',
        key: 'twoDMemeCache',
    },
    {
        title: 'UI显存(MB)',
        dataIndex: 'uiShowCache',
        key: 'uiShowCache',
    },
    {
        title: '贴图显存(MB)',
        dataIndex: 'picShowCache',
        key: 'picShowCache',
    },
    {
        title: '模型显存(MB)',
        dataIndex: 'modelShowCache',
        key: 'modelShowCache',
    },
    {
        title: '动作缓存(MB)',
        dataIndex: 'actionCache',
        key: 'actionCache',
    },
    {
        title: '特效Drawcall',
        dataIndex: 'effectDrawCall',
        key: 'effectDrawCall',
    },
]

export default class ComparePanel extends React.Component {
    constructor(props) {
        super(props)
        this.state = {

        }
    }

    componentDidMount() {
        let datasets = this.props.datasets || [];
        this.currentItemOverallArray = [];
        let self = this;
        let diff = {};
        datasets.map(function (dataset) {
            let ovall = JSON.parse(dataset.overall);
            for (let k in ovall) {
                let v = ovall[k];
                let v1 = diff[k];
                if (v1) {
                    diff[k] = Number(v) - Number(v1);
                } else {
                    diff[k] = Number(v)
                }
            }
            ovall.fileName = dataset.fileName;
            self.currentItemOverallArray.push(ovall);
        })

        diff['fileName'] = '上下差值'
        self.currentItemOverallArray.push(diff)

        this.setState({})
    }

    render() {
        let self = this;
        return <React.Fragment>
            <Table dataSource={self.currentItemOverallArray} columns={overallcolumns} />
        </React.Fragment>
    }

}